<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>
            任务调度系统
        </title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="format-detection" content="telephone=no">
        <link rel="stylesheet" href="./css/x-admin.css" media="all">
    </head>
    <body>
        <div class="x-nav">
            
            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
        </div>
        <div class="x-body">
           
            <xblock>
			<button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon">&#xe640;</i>批量删除</button>
			<button class="layui-btn" onclick="add('添加任务','add.html','800','600')"><i class="layui-icon">&#xe608;</i>添加</button>
			<span class="x-right" style="line-height:40px">共有数据：88 条</span></xblock>
            <table class="layui-table">
                <thead>
                    <tr>
                        <th>
                            <input type="checkbox" name="" value="">
                        </th>
                        <th>
                            任务id
                        </th>
						
                        <th>
                            任务名称
                        </th>
						
						 <th>
                            任务描述
                        </th>
						
						<th>
                            命令类型
                        </th>
						
                        <th>
                            执行命令
                        </th>
						
                        <th>
                            时间类型
                        </th>
						
						<th>
                            执行周期
                        </th>
						
                        <th>
                            添加时间
                        </th>
						
                        <th>
                            最后更新时间
                        </th>
						
                        <th>
                            操作
                        </th>
                    </tr>
                </thead>
                <tbody id="jobList">
                    
                </tbody>
            </table>

            <div id="page"></div>
        </div>
        <script src="./lib/layui/layui.js" charset="utf-8"></script>
        <script src="./js/x-layui.js" charset="utf-8"></script>
		<script src="./js/jquery.min.js" charset="utf-8"></script>
        <script>
			layui.use(['laydate','element','laypage','layer'], function(){
                $ = layui.jquery;//jquery
              laydate = layui.laydate;//日期插件
              lement = layui.element();//面包导航
              laypage = layui.laypage;//分页
              layer = layui.layer;//弹出层


              
              
              
            });
			
			
			jobHtml = '';
			
			$.get("/api/jobList", function(data){
				$.each(data,function(k,v){
					update_time = v['update_time']==0?v['add_time_format']:v['update_time_format'];
					logName = '/api/logView?logPath=' + v['logName'];
					runCmd = '/api/runCmd?cmd_type=' + v['cmd_type'] + "&cmd=" + v['cmd'];
					//pauseJob = '/api/pauseJob?job_uuid=' + v['job_uuid'];
					jobStats = '/api/jobStats?job_name=' + v['job_name'] ;
					
					if (v['stats'] ==1 ){
						pauseFunc = 'resumeJob';
						pauseName = '<button class="layui-btn" style ="background-color:#FF5722" onclick="resumeJob(\'' + v['job_name'] + '\')">恢复</button>';
						
						
					}else{
						pauseFunc = 'pauseJob';
						pauseName = '<button class="layui-btn" onclick="pauseJob(\'' + v['job_name'] + '\')">暂停</button>';
					
					}
					
					console.log(logName);
					jobHtml = jobHtml + '<tr>';
					jobHtml = jobHtml + '<td> <input type="checkbox" value="'+v['id']+'" name=""></td>';
					jobHtml = jobHtml + '<td>'+ v['id'] +'</td>';
					jobHtml = jobHtml + '<td>'+ v['job_name'] +'</td>';
					jobHtml = jobHtml + '<td>'+ v['job_desc'] +'</td>';
					jobHtml = jobHtml + '<td>'+ v['cmd_type'] +'</td>';
					jobHtml = jobHtml + '<td>'+ v['cmd'] +'</td>';
					jobHtml = jobHtml + '<td>'+ v['trig'] +'</td>';
					jobHtml = jobHtml + '<td>'+ v['job_time'] +'</td>';
					jobHtml = jobHtml + '<td>'+ v['add_time_format'] +'</td>';
					jobHtml = jobHtml + '<td>'+ update_time +'</td>';
					jobHtml = jobHtml + '<td class="td-manage">';
					jobHtml = jobHtml + '<button class="layui-btn" onclick="edit(\'任务修改\',\'edit.html?id=' + v['id'] + '\',\''+v['id']+'\',\'800\',\'600\')">修改</button>'; 
					jobHtml = jobHtml + '<button class="layui-btn" onclick="edit(\'任务状态\',\'' + jobStats + '\',\''+v['id']+'\',\'400\',\'400\')">状态</button>'; 
                    jobHtml = jobHtml + '<button class="layui-btn" onclick="window.open(\''+ runCmd +'\')">执行</button>'; 
					jobHtml = jobHtml + pauseName ; 
					jobHtml = jobHtml + '<button class="layui-btn" onclick="window.open(\''+ logName +'\')">查看日志</button>'; 
					jobHtml = jobHtml + '<button class="layui-btn" onclick="removeJob(\'' + v['job_name'] + '\')">删除</button>'; 
                    
                            
					jobHtml = jobHtml + '</td></tr>'
					
					
					
                            
                            
                            
                                
                            
                        
					
					
                        
                           
                        
				});
				
				$('#jobList').html(jobHtml);
				
				console.log(jobHtml);
					
			});
			
			function pauseJob(job_name){
				
				
				layer.confirm('您确定要暂停该任务吗？', {
					btn: ['确定','取消'] //按钮
				}, function()
				{
					$.get("/api/pauseJob?job_name=" + job_name, function(res){
				
							layer.alert(res.msg, {icon: 6},function () {
								parent.location.reload(); // 父页面刷新
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
							});
							return false;
						
				
					});
					
					//layer.closeAll('dialog');

				});
				
				return false;

			}
			
			
			function resumeJob(job_name){
				
				
				layer.confirm('您确定要恢复该任务吗？', {
					btn: ['确定','取消'] //按钮
				}, function()
				{
					$.get("/api/resumeJob?job_name=" + job_name, function(res){
				
							layer.alert(res.msg, {icon: 6},function () {
								parent.location.reload(); // 父页面刷新
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
							});
							return false;
						
				
					});
					
					//layer.closeAll('dialog');

				});
				
				return false;

			}
			
			
			function removeJob(job_name){
				
				
				layer.confirm('您确定要删除该任务吗？', {
					btn: ['确定','取消'] //按钮
				}, function()
				{
					$.get("/api/removeJob?job_name=" + job_name, function(res){
				
							layer.alert(res.msg, {icon: 6},function () {
								parent.location.reload(); // 父页面刷新
								var index = parent.layer.getFrameIndex(window.name);
								parent.layer.close(index);
							});
							return false;
						
				
					});
					
					//layer.closeAll('dialog');

				});
				
				return false;

			}
            

            //批量删除提交
             function delAll () {
                layer.confirm('确认要删除吗？',function(index){
                    //捉到所有被选中的，发异步进行删除
                    layer.msg('删除成功', {icon: 1});
                });
             }

             function question_show (argument) {
                layer.msg('可以跳到前台具体问题页面',{icon:1,time:1000});
             }
             /*添加*/
            function add(title,url,w,h){
                x_admin_show(title,url,w,h);
            }
            //编辑 
           function edit (title,url,id = 0,w,h) {
		   
				if(id ==0){
				
					layer.msg('任务id错误',{icon:1,time:1000});
					return ;
				}
                x_admin_show(title,url,w,h); 
            }

            /*删除*/
            function question_del(obj,id){
                layer.confirm('确认要删除吗？',function(index){
                    //发异步删除数据
                    $(obj).parents("tr").remove();
                    layer.msg('已删除!',{icon:1,time:1000});
                });
            }
            </script>
            
    </body>
</html>